package com.beiing.tianshuai.tianshuai.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.mine.entity.OrderTransportDataBean;

import java.util.List;

/**
 * Created by Administrator on 2018/4/7.
 */

public class OrderTransportAdapter extends RecyclerView.Adapter<OrderTransportAdapter.ViewHolder> {

    private List<OrderTransportDataBean.DataBean.NumberBean.ListBean> mOrderList;
    private Context mContext;

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTvTransportTime;
        TextView mTvTransportDate;
        TextView mTvTransportState;
        View mVRlv;

        public ViewHolder(View view) {
            super(view);
            mTvTransportTime = view.findViewById(R.id.tv_order_transport_time);
            mTvTransportDate = view.findViewById(R.id.tv_order_transport_date);
            mTvTransportState = view.findViewById(R.id.tv_order_transport_state);
            mVRlv = view.findViewById(R.id.v_rlv_horizontal);
        }
    }

    public OrderTransportAdapter(Context mContext, List<OrderTransportDataBean.DataBean.NumberBean.ListBean> mOrderList) {//List<MineOrderDataBean> mOrderList
        this.mContext = mContext;
        this.mOrderList = mOrderList;
    }

    @Override
    public OrderTransportAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = View.inflate(mContext, R.layout.item_order_transport_recyclerview, null);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(OrderTransportAdapter.ViewHolder holder, int position) {
        holder.mTvTransportTime.setText(mOrderList.get(position).getTime().substring(11, 16));
        holder.mTvTransportDate.setText(mOrderList.get(position).getTime().substring(0, 11));
        holder.mTvTransportState.setText(mOrderList.get(position).getStatus());
        //最后一个item设置隐藏分隔
        if (position == mOrderList.size()-1) {
            holder.mVRlv.setVisibility(View.GONE);
        }else{
            holder.mVRlv.setVisibility(View.VISIBLE);
        }
        //设置第一行字体颜色为黑色，其他为灰色
        if(position==0){
            holder.mTvTransportTime.setTextColor(Color.BLACK);
            holder.mTvTransportState.setTextColor(Color.BLACK);
        }else {
            holder.mTvTransportTime.setTextColor(ContextCompat.getColor(mContext,R.color.color_7f7f7f_content_text));
            holder.mTvTransportState.setTextColor(ContextCompat.getColor(mContext,R.color.color_7f7f7f_content_text));
        }
    }

    @Override
    public int getItemCount() {
        return mOrderList.size();
    }
}
